import request, { type ListQuery } from "@/utils/request";

const CITY_BASE_URL = "/api";

const CityAPI = {
  getCityList: (params: CityListParams) => {
    return request.get<any, CityType[]>(`${CITY_BASE_URL}/config/address/`, {
      params,
    });
  },
  addCity: (data: any) => {
    return request.post(`${CITY_BASE_URL}/config/address/`, data);
  },
  updateCity: (data: Partial<CityType>) => {
    return request.put(`${CITY_BASE_URL}/config/address/${data.id}/`, data);
  },
  deleteCity: (id: number) => {
    return request.delete(`${CITY_BASE_URL}/config/address//${id}/`);
  },
};

export type CityListParams = {
  parent_id?: number;
} & Partial<ListQuery>;

export type CityType = {
  id: number;
  name: string;
  full_name: string;
};

export default CityAPI;
